package com.demo.morning;

/**
 * @ClassName TestPriority
 * @Description TODO
 * @Author tianqinglong
 * @Date 9:54 2022/7/13
 * @Version 1.0
 **/
//测试线程的优先级
public class TestPriority {
    public static void main(String[] args) {
        //主线程默认优先级
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
        MyPrioriy myPrioriy=new MyPrioriy();
        Thread t1=new Thread(myPrioriy);
        Thread t2=new Thread(myPrioriy);
        Thread t3=new Thread(myPrioriy);
        Thread t4=new Thread(myPrioriy);
        Thread t5=new Thread(myPrioriy);
        Thread t6=new Thread(myPrioriy);
        //先设置优先级，再启动

        t2.setPriority(1);


        t3.setPriority(4);

        t4.setPriority(Thread.MAX_PRIORITY);//MAX_PRIORITY=10

        t5.setPriority(8);

        t6.setPriority(7);
        t1.start();
        t2.start();
        t3.start();
        t5.start();
        t6.start();
        t4.start();


    }

}

class MyPrioriy implements Runnable {

    @Override
    public void run() {

        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
    }

}
